import csv
import pandas as pd

df = pd.read_csv(r"D:\py\pythonProject\population-data\data\temp\分省常驻人口数据.csv", encoding="gbk")
df1= pd.read_csv(r"D:\py\pythonProject\population-data\data\temp\分省常驻人口数据.csv", encoding="gbk")

years = [str(year) for year in range(2023, 1999, -1)]
print(df1.head())

for i in range(len(years)-1):
    df1[years[i]+"年"] = df[years[i]+"年"] - df[years[i+1]+"年"]
    print(years[i]+"年")
    print(years[i+1]+"年")
    print(df[years[i]+"年"])
    print(df[years[i-1]+"年"])
    print(df1.head())
columns_to_keep = df1.loc[:, :'2001年'].columns
df1 = df1[columns_to_keep]
df1.to_csv(r"D:\py\pythonProject\population-data\data\temp\迁入迁出人口数据.csv", encoding="gbk")
